package com.xxx.modules.sys.service.impl;

import com.xxx.modules.sys.dao.SysUserMapper;
import com.xxx.modules.sys.domain.SysUserDomain;
import com.xxx.modules.sys.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/** 用户 ServiceImpl
 * Created by ChenXuefei on 2017/10/13.
 */
@Service("userService")
public class UserServiceImpl implements UserService{

    protected Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public List<String> queryAllPerms(Long userId) {
        return sysUserMapper.queryAllPerms(userId);
    }

    @Override
    public SysUserDomain queryUserByUserName(String userName) {
        SysUserDomain userDomain = new SysUserDomain();
        userDomain.setUsername(userName);
        List<SysUserDomain> sysUserDomains = sysUserMapper.queryByList(userDomain);
        if(sysUserDomains.size()>1){
            logger.error("【"+userName+"】"+"在数据库中不止存在一个");
        }
        //如未查询到，则直接返回null
        if(sysUserDomains.size()==0) {
            return null;
        }
        return sysUserDomains.get(0);
    }

    @Override
    public SysUserDomain queryUserByEmail(String email) {
        SysUserDomain userDomain = new SysUserDomain();
        userDomain.setUsername(email);
        List<SysUserDomain> sysUserDomains = sysUserMapper.queryByList(userDomain);
        if(sysUserDomains.size()>1){
            logger.error("【"+email+"】"+"在库中不止存在一个");
        }
        //如未查询到，则直接返回null
        if(sysUserDomains.size()==0) {
            return null;
        }
        return sysUserDomains.get(0);
    }

}
